package com.rainbow.entity;

import lombok.Data;

/**
 * @Author rainbow
 **/
@Data
public class Result<T> {
    private boolean success;
    private String message;
    private T data;
    private Integer code;

    public Result() {
    }

    public static <T> Result<T> getInstance() {
        return new Result<>();
    }


    private static <T> Result<T> result(boolean success, T data, String message, Integer code) {
        Result<T> result = getInstance();
        result.setSuccess(success);
        result.setMessage(message);
        result.setData(data);
        result.setCode(code);

        return result;
    }

    public static <T> Result<T> successResult(T data) {
        return result(true, data, null, 0);
    }

    public static <T> Result<T> successResult(String message) {
        return result(true, null, message, 0);
    }

    public static <T> Result<T> errorResult(String message) {
        return result(false, null, message, -1);
    }

    public static <T> Result<T> errorResult(String message, Integer code) {
        return result(false, null, message, code);
    }
}
